define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dts/material/storage/logthree/index' + location.search,
                    add_url: 'dts/material/storage/logthree/add',
                    edit_url: 'dts/material/storage/logthree/edit',
                    del_url: 'dts/material/storage/logthree/del',
                    multi_url: 'dts/material/storage/logthree/multi',
                    import_url: 'dts/material/storage/logthree/import',
                    table: 'dts_material_storage_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'category', title: __('Category'), searchList: {"daily":__('Category daily'),"expen":__('Category expen'),"food":__('Category food')}, operate: false, formatter: Table.api.formatter.normal},
                        {field: 'material_name', title: __('Material_id'), operate: 'LIKE'},
                        {field: 'quantity', title: __('Quantity'), operate: false},
                        {field: 'purchasetime', title: __('Purchasetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'unit_price', title: __('Unit_price'), operate: false},
                        {field: 'shelf_life', title: __('Shelf_life'), operate: 'LIKE'},
                        {field: 'saving', title: __('Saving'), searchList: {"1":__('Saving 1'),"2":__('Saving 2'),"3":__('Saving 3')}, formatter: Table.api.formatter.normal},
                        {field: 'traceability', title: __('Traceability'), searchList: {"0":__('Traceability 0'),"1":__('Traceability 1')}, formatter: Table.api.formatter.normal},
                        {field: 'qualified', title: __('Qualified'), searchList: {"0":__('Qualified 0'),"1":__('Qualified 1')}, formatter: Table.api.formatter.normal},
                        {field: 'shopping', title: __('Shopping'), searchList: {"0":__('Shopping 0'),"1":__('Shopping 1')}, formatter: Table.api.formatter.normal},
                        {field: 'packaging', title: __('Packaging'), searchList: {"0":__('Packaging 0'),"1":__('Packaging 1')}, formatter: Table.api.formatter.normal},
                        {field: 'organoleptic', title: __('Organoleptic'), searchList: {"0":__('Organoleptic 0'),"1":__('Organoleptic 1')}, formatter: Table.api.formatter.normal},
                        {field: 'voucher_file', title: __('Voucher_file'), operate: false, formatter: Table.api.formatter.files},
                        {field: 'shopping_file', title: __('Shopping_file'), operate: false, formatter: Table.api.formatter.files},
                        {field: 'accept.nickname', title: __('Accept_id'), operate: 'LIKE'},
                        {field: 'create.nickname', title: __('Create_id'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
